<?php
namespace app\index\controller;
use think\Controller;
use think\Db;

class Index extends Controller
{

    public function hello($name = 'ThinkPHP5')
    {
        return 'hello,' . $name;
    }

    /**
     * 公告详情页面
     * */
    public function index()
    {

        $id = input('id');

        $info = Db::name('article')->where(['id' => $id])->find();
        if($info['create_time']){
            $info['create_time'] = date('Y-m-d',$info['create_time']);
        }else{
            $info['create_time'] = "--";
        }
        if (mb_strlen($info['title'], 'utf8')>15) {
            $info['titles'] = mb_substr($info['title'], 0, 15, 'utf8').'...';
        }else{
            $info['titles'] = $info['title'];
        }

        $this->assign('data',$info);

        return $this->fetch();

    }


    /**
     * 公告详情页面
     * */
    public function article()
    {

        $id = input('id');

        $info = Db::name('help_article')->where(['id' => $id])->find();

        if($info['create_time']){
            $info['create_time'] = date('Y-m-d',$info['create_time']);
        }else{
            $info['create_time'] = "--";
        }

        if (mb_strlen($info['title'], 'utf8')>15) {
            $title = mb_substr($info['title'], 0, 15, 'utf8').'...';
        }else{
            $title = $info['title'];
        }
        $this->assign('data',$info);
        $this->assign('title',$title);

        return $this->fetch();

    }

     /**
     * 公告详情页面
     * */
    public function work()
    {

        $id = input('id');
        $uid = input('uid','');

        $info = Db::name('work_list')->where(['id' => $id])->find();

        if(!$info){
            $this->result('','-1','数据获取有误','json');
        }

        if($info['create_time']){
            $info['create_time'] = date('Y-m-d',$info['create_time']);
        }else{
            $info['create_time'] = "--";
        }

        if($uid){
            $map[] = ['work_id','=',$id];
            $map[] = ['user_id','=',$uid];

            $isSq = Db::name('apply_work')->where($map)->count();
            if($isSq == 0){
                $aCount = mb_strlen($info['contacts'],"utf-8");
                $aCount2 = mb_strlen($info['phone'],"utf-8");
                $dCount = mb_strlen($info['address'],"utf-8");
                $contacts = hidestr($info['contacts'],1,$aCount-2 );
                $phone = hidestr($info['phone'],2,$aCount2-2);
                $address = hidestr($info['address'],2,$dCount-2);
            }else{
                $contacts = $info['contacts'];
                $phone = $info['phone'];
                $address = $info['address'];
            }
        }else{
            $aCount = mb_strlen($info['contacts'],"utf-8");
            $aCount2 = mb_strlen($info['phone'],"utf-8");
            $dCount = mb_strlen($info['address'],"utf-8");
            $contacts = hidestr($info['contacts'],0,$aCount-2 );
            $phone = hidestr($info['phone'],2,$aCount2-2);
            $address = hidestr($info['address'],2,$dCount-2);
        }

        if(!empty($info['info'])){
            $arr = explode($info['contacts'],$info['info']);
            $infoS = $arr[0].$contacts.$arr[1];
            $arr2 = explode($info['phone'],$infoS);
            $infoS2 = $arr2[0].$phone.$arr2[1];
            $arr3 = explode($info['address'],$infoS2);
            $infoS3 = $arr3[0].$address.$arr3[1];
            $info['info'] = $infoS3;
        }

        if (mb_strlen($info['title'], 'utf8')>15) {
            $info['titles'] = mb_substr($info['title'], 0, 15, 'utf8').'...';
        }else{
            $info['titles'] = $info['title'];
        }

        $this->assign('data',$info);

        return $this->fetch();

    }

    /**
     * 党员帮扶中心
     * */
    public function dang()
    {

        $id = input('id');

        $info = Db::name('help_article')->where(['id' => $id])->find();
        if($info['create_time']){
            $info['create_time'] = date('Y-m-d',$info['create_time']);
        }else{
            $info['create_time'] = "--";
        }

        if (mb_strlen($info['title'], 'utf8')>15) {
            $info['titles'] = mb_substr($info['title'], 0, 15, 'utf8').'...';
        }else{
            $info['titles'] = $info['title'];
        }

        $this->assign('data',$info);

        return $this->fetch();

    }

}
